### -*- coding: utf-8 -*- #############################################
# Разработано компанией Ключевые Решения (http://keysolutions.ru/)
# Все права защищены, 2006-2007
#
# Developed by Key Solutions (http://keysolutions.ru/)
# All right reserved, 2006-2007
#######################################################################
"""DistributingView class for the Zope 3 based diplom

$Id: distributingview.py 74 2008-03-12 11:26:17Z Arvi3D $
"""
__author__  = "Arvid"
__license__ = "ZPL"
__version__ = "$Revision: 74 $"
__date__ = "$Date: 2008-03-12 11:26:17 +0000 (Wed, 12 Mar 2008) $"

from zope.interface import Interface
from zope.app.i18n import ZopeMessageFactory as _

DRAW_STEP = 10

from diplom.interfaces import IGenetic

class DistributingSelectionView(object) :
    """Distributing function view"""

    def lineCoordinates(self, method):
        variant = self.context
        h = variant.classLength/DRAW_STEP
        x = variant.front
        while(x <= variant.back):
            yield [x, method(x)]
            x += h

    def getDataSetScript(self):
        ga_weight, ga_paramlist = IGenetic(self.context).ga
        return '<script type="text/javascript"> var dataset = {"distributing selection":  %s, "distributing teoretical":  %s, "ga distributing": %s};</script>' \
                % (list(self.lineCoordinates(self.context.distributing)),
                   list(self.lineCoordinates(lambda x: self.context.teoreticalDistributing(x, self.context.weight, self.context.params))),
                   list(self.lineCoordinates(lambda x : self.context.teoreticalDistributing(x, ga_weight, ga_paramlist))),
                   )
